﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Xww.WindowsForm.Controls.Helpers {
    public static class TextBoxBaseHelper {
        public static void SetDragDropOfFileName(this TextBox textbox) {
            textbox.AllowDrop = true;
            textbox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            textbox.AutoCompleteSource = AutoCompleteSource.AllSystemSources;
            textbox.DragEnter += new DragEventHandler(textbox_DragEnter);
            textbox.DragDrop += new DragEventHandler(textbox_DragDrop);
        }
        public static void SetDragDropOfFileName(this IEnumerable<TextBox> textboxes) {
            foreach (TextBox textbox in textboxes) {
                SetDragDropOfFileName(textbox);
            }
        }

        static void textbox_DragEnter(object sender, DragEventArgs e) {
            e.Effect = DragDropEffects.All;
        }
        static void textbox_DragDrop(object sender, DragEventArgs e) {
            string[] fileNames = (string[])e.Data.GetData(DataFormats.FileDrop);
            ((TextBoxBase)sender).Text = fileNames[0];
        }


        //static void OnDragEnter(this Control control, DragEventArgs drgevent) {
        //    drgevent.Effect = DragDropEffects.All;
        //    control.OnDragEnter(drgevent);
        //}
        //static void OnDragDrop(this Control control, DragEventArgs drgevent) {
        //    control.OnDragDrop(drgevent);
        //    string[] fileNames = (string[])drgevent.Data.GetData(DataFormats.FileDrop);
        //    if (fileNames.Length > 0) {
        //        this.Text = fileNames[0];
        //    }
        //}

    }
}
